package player;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class PlayerSprite {
	private static String imageFilePath = "resources/model/";
	
	private static BufferedImage PLAYER_WEST;
	private static BufferedImage PLAYER_EAST;
	private static BufferedImage PLAYER_NORTH;
	private static BufferedImage PLAYER_SOUTH;
	
	static{
		try {
			
			PLAYER_WEST = ImageIO.read(new File(imageFilePath+"player/player_west.png"));
			PLAYER_EAST = ImageIO.read(new File(imageFilePath+"player/player_east.png"));
			PLAYER_NORTH = ImageIO.read(new File(imageFilePath+"player/player_north.png"));
			PLAYER_SOUTH = ImageIO.read(new File(imageFilePath+"player/player_south.png"));
			
		}
		catch (IOException e) {
			throw new IllegalArgumentException(e + " -> Error loading images.");
		}
	}
	
	private Player player;
	
	/**
	 * Initializes the {@link PlayerSprite} with a {@link Player}-object.
	 * @param playerObject
	 */
	PlayerSprite(Player playerObject){
		player = playerObject;
	}
	
	/**
	 * Returns the sprite corresponding to the player's current facing.
	 * @return
	 */
	BufferedImage getImage(){
		switch (player.getFacing()) {
		case NORTH:			
			return PLAYER_NORTH;
		case EAST:
			return PLAYER_EAST;
		case SOUTH:
			return PLAYER_SOUTH;
		case WEST:
			return PLAYER_WEST;
		default:
			return null;
		}
	}

}
